//
//  AuthenTypePhoneVM.swift
//  kxf
//
//  Created by Mac on 2024/3/6.
//

import Foundation
import UIKit

class AuthenTypePhoneVM: UIView {
    
    let selfHeight = kFitWidth(48)

    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: 0, y: frame.origin.y, width: SCREEN_WIDHT, height: selfHeight))
        self.backgroundColor = .white
        self.isUserInteractionEnabled = true
        self.layer.cornerRadius = kFitWidth(8)
        self.clipsToBounds = true
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var titleVm : RegisterViewHeadTitleVM = {
        let vm = RegisterViewHeadTitleVM.init(frame: CGRect.init(x: 0, y: kFitWidth(2), width: 0, height: 0))
        vm.titleLabel.text = "商户手机号"
        return vm
    }()
    lazy var textField : UITextField = {
        let text = UITextField()
        text.keyboardType = .numberPad
        text.placeholder = "请输入商户手机号"
        text.delegate = self
        text.textAlignment = .right
        
        return text
    }()
}

extension AuthenTypePhoneVM{
    func initUI() {
        addSubview(titleVm)
        addSubview(textField)
        
        textField.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-20))
            make.centerY.lessThanOrEqualToSuperview()
            make.width.equalTo(kFitWidth(160))
            make.height.equalToSuperview()
        }
    }
    
}


extension AuthenTypePhoneVM:UITextFieldDelegate{
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        if string == "" {
            return true
        }
        if textField.text?.count ?? 0 > 10{
            return false
        }
        return true
    }
}
